# Python 2.6.4
# Project Euler, Problem 54
# Copyright 2010 Talha Zaman


class Card:
    ranks = {'2':0, '3':1, '4':2, '5':3, '6':4, '7':5, '8':6, \
             '9':7, 'T':8, 'J':9, 'Q':10, 'K':11, 'A':12}
    def __init__(self, card):
        self.suit = card[1]
        self.rank = card[0]
    def __repr__(self):
        return self.rank + self.suit
    def __cmp__(self, other):
        return Card.ranks[self.rank] - Card.ranks[other.rank]
    def __index__(self):
        return Card.ranks[self.rank]

class Hand:
    def __init__(self, cardlist):
        self.cardvals = [0]*13
        self.cards = [Card(x) for x in cardlist]
        for c in self.cards: self.cardvals[c] += 1
    def __repr__(self):
        return str(self.cards)
    def flush(self):
        return all(s.suit==self.cards[0].suit for s in self.cards[1:])
    def straight(self):
        for i in range(0, 8):
            if all(self.cardvals[i:i+5]): return True
        if all(self.cardvals[0:4]) and self.cardvals[12]: return True
        return False
    def __cmp__(self, other):
        val = self.setvalue() - other.setvalue()
        if val: return val
        if self.setvalue() == 1:
            for i in range(12,-1,-1):
                face = self.cardvals[i] - other.cardvals[i]
                if face: return face
        if self.setvalue() == 2:
            pair = self.cardvals.index(2) - other.cardvals.index(2)
            if pair: return pair
            for i in range(12,-1,-1):
                face = self.cardvals[i] - other.cardvals[i]
                if face: return face
        return 0
    def setvalue(self):
        if self.flush() and self.straight():
            return 9
        elif max(self.cardvals) == 4:
            return 8
        elif 3 in self.cardvals and 2 in self.cardvals:
            return 7
        elif self.flush():
            return 6
        elif self.straight():
            return 5
        elif 3 in self.cardvals:
            return 4
        elif self.cardvals.count(2) == 2:
            return 3
        elif 2 in self.cardvals:
            return 2
        else:
            return 1
    
data = [line.strip().split(" ") for line in open("poker.txt").readlines()]
hands = [[Hand(line[:5]), Hand(line[5:])] for line in data]
p1, p2, d = 0, 0, 0
for i in range(1000):
	if hands[i][0] > hands[i][1]: p1 += 1
	elif hands[i][0] < hands[i][1]: p2 += 1
	else: d += 1
print p1, p2, d
